<template>
  <div class="wrap">
      <el-table
        :data="tableData"
        style="width: 100%;"
        max-height="1000">
        <el-table-column
          :formatter="formatDate"
          prop="fktjsj"
          label="日期"
          width="300">
        </el-table-column>
        <el-table-column
          prop="fkid"
          label="反馈id"
          width="200">
        </el-table-column>

        <el-table-column
          prop="fknr"
          label="反馈内容"
          width="200">
        </el-table-column>
        <el-table-column width="150"></el-table-column>
        <el-table-column
          prop="fktjrid"
          label="反馈人id"
          width="250">
        </el-table-column>
        <el-table-column
          label="操作"
          width="100">
          <template slot-scope="scope">
            <el-button
              @click.native.prevent="deleteRow(scope.$index, tableData)"
              type="danger"
              size="small">
              移除
            </el-button>
          </template>
        </el-table-column>

      </el-table>
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[5, 10]"
        :page-size="5"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total">
      </el-pagination>

  </div>

</template>

<script>
  import {feedback, delfeedback} from '@/api/admin/feedback'
    export default {
        name: "index",
      data() {
        return {
          tableData: [],
          getfkid: Object,
          currentPage: 4,
          total:1,
          pageSize:5
        }
      },
      created() {
        //获取所有反馈信息
        this.getfeedback()
      },
      methods: {
        handleSizeChange(val) {
          feedback(1,val).then(res =>{
            this.pageSize=val
            this.tableData = res.data.feedback
            this.total = res.data.total
            console.log(res,'打印获取所有反馈信息成功')
          }).catch(err =>{
            console.log(err,'打印获取所有反馈信息失败')
          })
          console.log(`每页 ${val} 条`);
        },
        handleCurrentChange(val) {
          feedback(val,this.pageSize).then(res =>{
            this.tableData = res.data.feedback
            this.total = res.data.total
            console.log(res,'打印获取所有反馈信息成功')
          }).catch(err =>{
            console.log(err,'打印获取所有反馈信息失败')
          })
        },

        //预约提示变量 1搜索提示信息 2预约成功提示 3预约失败提示
        open(tips) {
          if (tips == 1) {
            this.$alert('<strong> 反 馈 修 改 成 功 。 </strong>', '删除成功！！', {
              dangerouslyUseHTMLString: true
            })
          }else {
            this.$alert('<strong> 反 馈 修 改 失 败 。 </strong>', '修改失败！！', {
              dangerouslyUseHTMLString: true
            })
          }
        },
        formatDate:function(row, column, cellValue, index) {
          let date = new Date(cellValue);
          let Y = date.getFullYear() + '-';
          let M = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) + '-' : date.getMonth() + 1 + '-';
          let D = date.getDate() < 10 ? '0' + date.getDate() + ' ' : date.getDate() + ' ';
          let h = date.getHours() < 10 ? '0' + date.getHours() + ':' : date.getHours() + ':';
          let m = date.getMinutes()  < 10 ? '0' + date.getMinutes() + ':' : date.getMinutes() + ':';
          let s = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds();
          return Y + M + D + h + m + s;
        },
          getfeedback() {
            feedback(1,5).then(res =>{
              this.tableData = res.data.feedback
              this.total = res.data.total
              console.log(res,'打印获取所有反馈信息成功')
            }).catch(err =>{
              console.log(err,'打印获取所有反馈信息失败')
            })
          },
        deleteRow(index, rows) {
          this.getfkid = rows.slice(index, index + 1)[0].fkid
          console.log(rows.slice(index, index + 1)[0].fkid)
          delfeedback(this.getfkid).then(res =>{
            this.open(1)
          }).catch(err=>{
            this.open()
          })
          this.getfeedback()
        }
      },
    }
</script>

<style lang="scss" scoped>

  .wrap{
    width: 1400%;
    height: 100%;

    margin-left: 5%;
    margin-top: 2%;
    /*background-color: #3a835d;*/
  }
  .el-table{
    margin: 20px auto;
    width: 100%;
  }


</style>
